package com.apes.fn.server.servicePlan.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.BaseModel;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import com.apes.framework.util.MD5Util;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * @program: apes-server
 * @description:
 * @author: czs
 * @create: 2022-09-18 14:54
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = GetPriceLogger.CONST_TABLE_NAME, indexes ={
        @Index(name = "IDX_CAR_PRODUCT", columnList = "car_license, product_id", unique = false),
        @Index(name = "IDX_PRICE_LOGGER_PRODUCT", columnList = "product_id", unique = false),
        @Index(name = "IDX_PRICE_LOGGER_CAR", columnList = "car_license", unique = false)
})
public class GetPriceLogger extends BaseModel {
    public static final String CONST_TABLE_NAME = "get_price_logger";

    @Id
    @Column(name = "id", nullable = false, length = 24)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "价格日志编码", padding = 12)
    private String id;

    @Column(name = "conditionStrategy_id", nullable = false, length = 32)
    @Comment("执行过程id")
    private String conditionStrategyId;

    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "condition_param", columnDefinition = "CLOB")
    @Comment("条件参数")
    private String conditionParam;

    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "condition_result", columnDefinition = "CLOB")
    @Comment("条件返回结果")
    private String conditionResult;

    /*** 车辆 ***/
    @Column(name = "car_license", length = 64)
    @Comment("车牌号码")
    private String carLicense;

    @Column(name = "product_id", length = 64, nullable = false)
    @Comment("商品编码")
    private String productId;

    @Column(name = "dept_id", length = 64)
    @Comment("取价门店")
    private String deptId;

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "sys_date")
    @Comment("条件日期")
    private Date sysDate;

    @Column(name = "valid",  columnDefinition = "number(1,0) default 1")
    @Comment("有效标记")
    private boolean valid = true; //有效
}
